<template>
  <div>
    <input class="mint-button mint-button--default mint-button--small" type="button" id="btn35" value="获取验证码" @click="sendreciprocal(number,oldnumber)" />
  </div>

</template>
<script>
import axios from "axios";
import { Indicator } from "mint-ui";
import { Toast } from "mint-ui";
export default {
  props: ["number", "oldnumber"],
  data() {
    return {
      flag: ""
    };
  },
  methods: {
    sendreciprocal(number, oldnumber) {
      let telephoneNumber = number;
      let oldtelephoneNumber = oldnumber;
      if (telephoneNumber === oldtelephoneNumber) {
        Indicator.close();
        let instance = Toast({
          message: "请输入新手机号"
        });
        setTimeout(() => {
          instance.close();
        }, 2000);
      } else {
        if (telephoneNumber === "" || telephoneNumber === null) {
          Indicator.close();
          let instance = Toast({
            message: "请输入手机号"
          });
          setTimeout(() => {
            instance.close();
          }, 2000);
        } else {
          if (telephoneNumber && /^1(3|4|5|7|8)\d{9}$/.test(telephoneNumber)) {
            this.$options.methods.reciprocal();
            this.$emit("setfalg", "1");
          } else {
            Indicator.close();
            let instance = Toast({
              message: "请输入正确的手机号"
            });
            setTimeout(() => {
              instance.close();
            }, 2000);
          }
        }
      }
    },

    reciprocal() {
      var count = 60;
      var countdown = setInterval(CountDown, 1000);
      function CountDown() {
        $("#btn35").attr("disabled", true);
        $("#btn35").val("已发送" + count);
        if (count == 0) {
          $("#btn35")
            .val("获取验证码")
            .removeAttr("disabled");
          clearInterval(countdown);
        }
        count--;
      }
    }
  }
};
</script>
